package com.sinochem.yunlian.ship.base.rpc;

import com.sinochem.yunlian.ship.api.vo.bs.BsPortalIndexVo;
import com.sinochem.yunlian.ship.base.biz.BsProtalIndexBiz;
import com.sinochem.yunlian.ship.base.entity.BsPortalIndex;
import com.sinochem.yunlian.ship.common.annotation.IgnoreToken;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by jayway on 2017/12/19.
 */
@IgnoreToken
@RestController
@RequestMapping("/api/portal")
public class BsPortalRest {
    @Autowired
    private BsProtalIndexBiz protalIndexBiz;

    @RequestMapping(value = "newestInfo",method = RequestMethod.GET)
    public BsPortalIndexVo getNewest(){
        BsPortalIndexVo vo = new BsPortalIndexVo();
        BsPortalIndex portalIndex = protalIndexBiz.getLastInfo();
        if(portalIndex!=null){
            BeanUtils.copyProperties(portalIndex,vo);
        }else{
            vo.setShipEmptyCount(0);
            vo.setShipCount(0);
            vo.setMeterialCount(0);
            vo.setTotalShipEmpty(0);
        }
        return vo;
    }


    @RequestMapping(value = "addPortalIndex",method = RequestMethod.POST)
    public String addIndex(@RequestBody BsPortalIndexVo vo){
        BsPortalIndex index = new BsPortalIndex();
        BeanUtils.copyProperties(vo,index);
        protalIndexBiz.insert(index);
        return "ok";
    }
}
